package com.lyz.collectionDemo.collection;

import java.util.*;

/**
 * @ClassName CollectionD1
 * @Description Collection集合遍历
 * @Author 2214361854
 * @Date 2022/2/21 14:07
 * @Version 1.0
 */
public class CollectionD2 {
    public static void main(String[] args) {
        Collection<String> lists = new ArrayList<>();
        lists.add("java");
        lists.add("set");
        lists.add("java");
        lists.add("123");
        System.out.println(lists);

        //迭代器遍历
        Iterator<String> iterator = lists.iterator();
        while (iterator.hasNext()) {
            String ele = iterator.next();
            System.out.println(ele);
        }
        System.out.println("================");

        //foreach遍历 增强for循环
        for (String i:lists) {
            System.out.println(i);
        }
        System.out.println("================");

        //lambda遍历
//        lists.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });

//        lists.forEach(s -> System.out.println(s));

//        方法引用
        lists.forEach(System.out::println);

    }
}
